package com.time.sky.controller;

import com.alibaba.druid.support.json.JSONUtils;

import com.time.sky.entity.User;
import com.time.sky.result.Result;
import com.time.sky.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.util.HtmlUtils;


//跨域
@CrossOrigin
//json字符串注解
@RestController
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("selectUser")
    @ResponseBody
    public Result login(@RequestBody User requestUser) {
        // 对 html 标签进行转义，防止 XSS 攻击
        String username = requestUser.getUsername();
        username = HtmlUtils.htmlEscape(username);
        User user = userService.selectUser( username, requestUser.getPassword() );
        if (user==null  ) {
            String message = "账号密码错误";
            System.out.println("test");
            return new Result(400);
        } else {
            return new Result(200);
        }
    }
}
